import {
  _decorator,
  Color,
  Component,
  Label,
  Node,
  Sprite,
  UITransform,
} from 'cc';
const { ccclass, property } = _decorator;

@ccclass('DanmuChoicesItemController')
export class DanmuChoicesItemController extends Component {
  @property(Sprite)
  bg: Sprite | null = null;
  @property(Label)
  cardIndex: Label | null = null;
  @property(Label)
  danmuCount: Label | null = null;

  colors = ['#FF0000', '#00FF00', '#0000FF', '#9d00ff', '#A0D0FF'];

  start() {}

  render(cardIndex: number, danmuCount: number, width: number, used: boolean) {
    this.node.active = true;
    this.cardIndex.string = cardIndex.toString();
    this.danmuCount.string = danmuCount.toString();
    const color = used ? '#6e6e6e' : this.colors[cardIndex];
    this.bg.color = new Color().fromHEX(color);
    const uiTrans = this.node.getComponent(UITransform);
    uiTrans.setContentSize(width, uiTrans.height);
  }

  update(deltaTime: number) {}
}
